package com.dek.ssm.ch11;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.dek.ssm.ch11.aop.AopConfig;
import com.dek.ssm.ch11.game.GameService;
import com.dek.ssm.ch11.game.GameVerifier;

public class Ch11Main {
	
	public static void main(String[] args) {
		ApplicationContext context = new AnnotationConfigApplicationContext(AopConfig.class);
		
		GameService gameService = context.getBean(GameService.class);
		
		/**
		 * obj .getClass().getInterfaces（）意味着代理对象挂在多个接口之下，换句话说，只要 Spring
		 *	AOP 让代理对象挂到 RoleService 和 RoleVerifier 两个接口之下，那么就可以把对应的 Bean
		 *	通过强制转换，让其在 RoleService 和 RoleVerifier 之间相互转换了
		 */
		GameVerifier gameVerifier = (GameVerifier) gameService;
		
		String name = "dek";
		String name1 = null;
		if (gameVerifier.verify(name)) {
			gameService.printGame(name);
		}
		
		if (gameVerifier.verify(name1)) {
			gameService.printGame(name1);
		}
		
//		gameService.printGame("dek");
//		
//		gameService.printGame(null);
		
		

		ApplicationContext context2 = new AnnotationConfigApplicationContext(com.dek.ssm.ch11.multi.AopConfig.class);
//		GameService gameService = context.getBean(GameService.class);
	}
	
}
